<template>
	<zui-box>
		<zui-navbar title="申请代理"></zui-navbar>
		<u-gap height="20rpx"></u-gap>
		<view class="zui-form">
			<view class="upimgs">
				<view class="tit">请上传营业执照</view>
				<view class="up_img" @click="upimgs">
					<image src="../../static/img/up_img.png" class="noimg" mode="" v-if="!business_license"></image>
					<image :src="httpPath + business_license" mode="" v-else></image>
				</view>
			</view>
		</view>
		<zui-button bgColor="#AA334F" @fun="save">申请</zui-button>
	</zui-box>
</template>

<script>
export default {
	data() {
		return {
			business_license: ''
		};
	},
	onShow() {},
	methods: {
		upimgs() {
			let that = this;
			uni.chooseImage({
				count: 1,
				sourceType: ['album '],
				success: res => {
					const tempFilePaths = res.tempFilePaths[0];
					console.log(tempFilePaths);
					uni.showLoading({
						title: '上传中'
					});
					uni.uploadFile({
						url: `${that.httpPath}/app/tool/uploadImage`,
						filePath: tempFilePaths,
						name: 'image',
						success: res => {
							uni.hideLoading();
							let data = JSON.parse(res.data);
							if (data.code == 1) {
								this.business_license = `${data.data}`;
							} else {
								uni.showToast({
									title: data.msg,
									icon: 'none',
									duration: 2000
								});
							}
						},
						fail: err => {
							uni.hideLoading();
							uni.showToast({
								icon: 'none',
								title: '上传失败'
							});
						}
					});
				}
			});
		},
		save() {
			if (!this.business_license) return this.say('请上传营业执照');
			uni.$u.http
				.post(
					'/app/user/applyAgent',
					{
						business_license: this.business_license
					},
					{
						params: {},
						custom: {
							auth: true,
							toast: true,
							catch: true
						}
					}
				)
				.then(res => {
					uni.$u.toast('成功');
					setTimeout(() => {
						uni.navigateBack();
					}, 1200);
				})
				.catch(err => {});
		}
	}
};
</script>

<style lang="scss" scoped>
.zui-form {
	width: 100%;
	box-sizing: border-box;
	padding: 0 30rpx;
	.zui_input {
		box-sizing: border-box;
		padding: 0 0 0 20rpx;
		border-radius: 104rpx;
		background: #232539;
		margin-bottom: 20rpx;
		/deep/.u-input__content {
			box-sizing: border-box;
			padding: 0 30rpx;
		}
		/deep/.u-input__content__field-wrapper__field {
			height: 104rpx !important;
		}
	}
}
.upimgs {
	width: 100%;
	border-radius: 20rpx;
	background: #fff;
	padding: 30rpx;
	box-sizing: border-box;
	.tit {
		width: 100%;
		color: #999;
		font-size: 26rpx;
	}
	.up_img {
		width: 100%;
		padding: 30rpx 30rpx 0;
		box-sizing: border-box;
		min-height: 200rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		.noimg {
			width: 200rpx;
			height: 200rpx;
		}
		image {
			max-width: 90%;
			min-width: 160rpx;
			min-height: 160rpx;
		}
	}
}
</style>
